import produce from "immer"

const initState = {
  size: localStorage.getItem("size") || "middle",
  lang: localStorage.getItem("lang") || navigator.language.split("-")[0],
  color: localStorage.getItem("color") || "#40a9ff"
}

export default (state = initState, { type, payload }) => {
  return produce(state, newState => {
    switch (type) {
      case "APP_SIZE":
        newState.size = payload;
        localStorage.setItem("size", payload)
        break;
      case "APP_LANG":
        newState.lang = payload;
        localStorage.setItem("lang", payload)
        break;
      case "APP_COLOR":
        newState.color = payload;
        localStorage.setItem("color", payload)
        break;
    }
  })
}

